import {createStore} from 'redux';
import mutations from './actions'

//定义State数据
let defaultState = {count:0,back:false,title:'推荐', selectBarIndex:0,isTabBarShow:true};

//定义一个reducer函数,该变量是一个函数,该函数用来定义具体state数据源的更改操作
const reducer = function(state = defaultState,action){
    let newState = null;
    // 判断是否需要外部参数干预state值
    if(action.hasOwnProperty('params')){
        newState = mutations[action.type] ? mutations[action.type](state,action.params):state ;
    }else{
// 如果params为空说明外界更改数据不需要依托外部传递的数据
        newState = mutations[action.type] ? mutations[action.type](state) : state;
    }
    return {...state,...newState} 

}
let store = createStore(reducer);
export default store;